<?php 

namespace Admin\Controller;
use Admin\Controller\BaseController;

/**
 * 数据模型管理控制器
 * @author 艾逗笔<765532665@qq.com>
 */
class ModelController extends BaseController {

	/**
	 * 初始化
	 * @author 艾逗笔<765532665@qq.com>
	 */
	public function _initialize() {
		$res['title'] = '模型列表';
		$res['url'] = U('lists');
		$res['class'] = ACTION_NAME == 'lists' ? 'active' : '';
		$nav[] = $res;

		$res['title'] = '新增模型';
		$res['url'] = U('add');
		$res['class'] = ACTION_NAME == 'add' ? 'active' : 'hide';
		$nav[] = $res;

		$this->assign('nav', $nav);
	}

	/**
	 * 数据模型列表
	 * @author 艾逗笔<765532665@qq.com>
	 */
	public function lists() {
		$lists = M('model')->where(array('status'=>1))->order('create_time desc')->field(true)->select();
		$this->assign('lists', $lists);
		$this->display();
	}

	/**
	 * 新增数据模型
	 * @author 艾逗笔<765532665@qq.com>
	 */
	public function add() {
		if (IS_AJAX) {
			$Model = D('Model');
			if (!$Model->create()) {
				$return =  array(
					'rsm' => null,
					'errno' => -1,
					'err' => $Model->getError(),
				);
			} else {
				$Model->add();
				$return =  array(
					'rsm' => array('url'=>U('lists')),
					'errno' => 1,
					'err' => '新增模型成功',
				);
			}
			$this->ajaxReturn($return);
			
		}
		$this->display();
	}
}



?>